﻿using System;

using System.Text;
using IAM.Interface.Model.Interface;
using System.Web;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 响应消息包头
    /// </summary>
    [Serializable]
    public class ResponseData : AbstractConvertObject, IConvertXml
    {
        #region 属性
        private string _transactionid = "";
        private DateTime _responsetime =System.DateTime.Now;
        private int _statuscode = 200;
        private string _returnmessage = "";

        /// <summary>
        /// 发起请求的事务ID
        /// </summary>
        public string TransactionID
        {
            set
            {
                _transactionid = value;
            }
            get
            {
                return _transactionid;
            }
        }
        /// <summary>
        /// 响应请求的时间戳
        /// </summary>
        public DateTime ResponseTime
        {
            set
            {
                _responsetime = value;
            }
            get
            {
                return _responsetime;
            }
        }
        /// <summary>
        /// 响应状态编码
        /// </summary>
        public int StatusCode
        {
            set
            {
                _statuscode = value;
            }
            get
            {
                return _statuscode;
            }
        }
        /// <summary>
        /// 请求响应结果说明信息
        /// </summary>
        public string ReturnMessage
        {
            set
            {
                _returnmessage = value;
            }
            get
            {
                return _returnmessage;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<ResponseData");
                _xml.Append(" TransactionID=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.TransactionID) + "\"");
                _xml.Append(" ResponseTime=\"" + this.ResponseTime + "\"");
                _xml.Append(" StatusCode=\"" + this.StatusCode.ToString()+ "\"");
                _xml.Append(" ReturnMessage=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.ReturnMessage )+ "\"");
                _xml.Append("  >");
                return _xml.ToString();
            }


        }
        public string XMLFinis
        {
            get
            {
                return "</ResponseData>";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            //1.获取当前结点
            this.TransactionID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["TransactionID"].InnerText);
            this.ResponseTime = System.Convert.ToDateTime(this.CurrentXmlNode.Attributes["ResponseTime"].InnerText);
            this.StatusCode = int.Parse(this.CurrentXmlNode.Attributes["StatusCode"].InnerText);
            this.ReturnMessage = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ReturnMessage"].InnerText);
          
            return this;
        }
        #endregion
    }

}
